package com.jiazhong.spring.rocketmq.顺序消息.生产;

import lombok.SneakyThrows;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

public class 全局消息发送 {

    @SneakyThrows
    public static void main(String[] args) {
        DefaultMQProducer producer = new DefaultMQProducer("producer_group_a");
        producer.setNamesrvAddr("124.220.170.254:9876");
        producer.start();

        for (int i = 1; i < 21; i++) {
            String topic = "TopicA";
            String tags = "global";
            String body = "Hello,全局有序," + i;
            Message message = new Message(topic, tags, body.getBytes());
            producer.send(message, (list, message1, o) -> list.get(0), 0);
        }
        producer.shutdown();
    }
}
